package com.qfedu.openplateform.stack.service.impl;

import com.qfedu.openplateform.common.entity.WarehouseProduct;
import com.qfedu.openplateform.stack.dao.WarehouseProductMapper;
import com.qfedu.openplateform.stack.service.WarehouseProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class WarehouseProductServiceImpl implements WarehouseProductService {
    @Autowired
    private WarehouseProductMapper warehouseProductMapper;

    @Override
    public boolean updateCurrentCnt(WarehouseProduct warehouseProduct) {
        Integer id = warehouseProduct.getProductId(); // 商品 id
        Integer temp = warehouseProduct.getCurrentCnt(); // 库存变化
        Integer currentCnt = warehouseProductMapper.getCurrentCntByProductId(id); // 剩余库存
        if (currentCnt + temp > 0) {
            warehouseProduct.setCurrentCnt(currentCnt + temp);
            warehouseProductMapper.updateProduct(warehouseProduct);
            return true;
        }
        return false;
    }
}
